import React, {Component} from 'react';
import NewIncreased from '../../../../../public/components/NewIncreased';
import {ajax, promptBox, toast} from 'nc-lightapp-front';
import {transRadio, saveValidate} from 'src/hrpub/common/utils/utils';
import './index.less';
import {chectFormAction, setFormAttrAndValue} from '../../../../../public/functions/checkFormAction';
import deepCopy from 'src/hrpub/common/utils/deep-copy';

let pk_psnjobs = []

class AddNew extends Component {
    constructor(props) {
        super(props);
        this.state = {
            setModalVisible: false,//新增弹窗显示隐藏
            formVisible: false,
            listVisible: false,
            editColumn: [], // 可编辑的键
            contractnum: '', // 变更前合同编号
            step: 0,
            pk_psnjobs: [],
            keyValues: [],
            form: this.props.form,
            agreementType: 'postcont',
            baseForm: ''
        }

        this.prevHandle= this.prevHandle.bind(this);
        this.nextHandle= this.nextHandle.bind(this);
        this.doneHandle= this.doneHandle.bind(this);
        this.onClose = this.onClose.bind(this);
        this.beforeEventHandle = this.beforeEventHandle.bind(this);
        this.afterEventHandle = this.afterEventHandle.bind(this);
    }

    // 设置新增弹窗显示隐藏
    setNewIncreasedDis(setModalVisible) {
        let {agreementType} = this.props;
        this.setState({
            setModalVisible,
            formVisible: false,
            listVisible: false,
        },()=>{
            setModalVisible ? this.newIncreased.setAgreementType(agreementType) :'';
        })
    }

    // 下一步方法
    nextHandle(selectData, agreementType) {
        let json = this.props.json;
        this.setState({
            isInterrupt: false
        });
        let initParam = {
            agreementType: this.state.agreementType,
            baseForm: "agreementCard",
            beforeForm: this.state.agreementType + "CardBefore",
            afterForm: this.state.agreementType + "CardAfter"
        };
        // this.props.setDataBeforeFormKey(initParam);
        this.setState({
            agreementType: agreementType,
            listVisible: true,
            formVisible: false,
        });
        let props = this.props;
        let {pkOrg, editTable} = props;
        pk_psnjobs = selectData.map(function (item) {
            return item.data.values.pk_psnjob.value
        });
        let paramObj = {
            pageCode: '60110503p',
            areaCode: 'releasecontlist',
            pk_psnjobs: pk_psnjobs,
            agreementType: agreementType,
            pk_org: pkOrg
        };
        if (!this.state.listVisible) { //第一个下一步
            this.setState({
                firstSelectData: selectData,
            });
            ajax({
                url: '/nccloud/hrcm/agreement/AgreementSelectContAction.do',
                data: paramObj,
                success: (result) => {
                    if (result.success) {
                        let rows = result.data.resultData.releasecontlist;
                        this.setState({
                            listVisible: true,
                            formVisible: false,
                            rows: rows,
                            tableId: 'releasecontlist'
                        }, function () {
                            editTable.setTableData('releasecontlist', rows);
                            editTable.selectAllRows('releasecontlist', true);
                            this.forceUpdate()
                        })
                    }
                }
            })
        } else { //第二个下一步
            let props = this.props;
            let {form} = props;
            if (selectData.length < 1) {
                promptBox({
                    color: 'warning',
                    title: json['cm6011-000144'], /*错误信息*/
                    content: json['cm6011-000145'],/*请选择协议！*/
                    beSureBtnName: json['cm6011-000129'], /*关闭*/
                    hasCloseBtn: true,
                    noFooter: false,
                    noCancelBtn: true,
                });
                this.setState({
                    isInterrupt: false
                });
                return;
            }
            let pk_agreements = selectData.map(function (item) {
                return item.data.values.pk_cont.value
            });
            pk_psnjobs = selectData.map(function (item) {
                return item.data.values.pk_psnjob.value
            });
            this.setState({
                addAgreementPks: pk_agreements,
            });
            let baseAreaCode = 'agreementCard';
            // if(agreementType === 'traincont'){
            //     baseAreaCode = 'traincontBaseCard' ;
            // }
            let paramObj = {
                pageCode: '60110503p',
                appCode: '60110503',
                areaCode: baseAreaCode + ',' + agreementType + 'CardBefore,' + agreementType + 'CardAfter',
                pk_psnjobs: pk_psnjobs,
                agreementType: agreementType,
                pk_agreements: pk_agreements,
                pk_org:pkOrg
            };
            props.setCardColumnShow(); //解决新增底部的卡片界面变化
            ajax({
                url: '/nccloud/hrcm/common/DataInitAction.do',
                data: paramObj,
                success: (result) => {
                    let data = result.data;
                    if (result.success && data) {
                        let resultData = data.resultData
                        let rows = null;
                        // if (resultData.hasOwnProperty('agreementCard_add')) {
                            rows = resultData.agreementCard_add.rows;
                        // } else {
                        //     rows = resultData.traincontBaseCard_add.rows;
                        // }
                        // let month = parseInt(new Date().getMonth()) + 1;
                        // rows[0].values.signdate.value = new Date().getFullYear() + "-" + month + "-" + new Date().getDate()
                        let template = data.template;
                        let formrelationData = data.formrelation;
                        let baseForm = 'agreementCard_add';
                        template.formrelation = formrelationData;
                        // if (agreementType === 'traincont') {
                        //     baseForm = 'traincontBaseCard_add'
                        // }
                        // if (agreementType === 'postcont') {
                        //     template = {
                        //         postcontCardAfter_add: data.template.postcontCardAfter_add,
                        //         agreementCard_add: data.template.agreementCard_add,
                        //         postcontCardBefore_add: data.template.postcontCardBefore_add,
                        //         formrelation: {agreementCard_add: ['postcontCardBefore_add', 'postcontCardAfter_add']}
                        //     };
                        // } else if (agreementType === 'secrerycont') {
                        //     template = {
                        //         secrerycontCardAfter_add: data.template.secrerycontCardAfter_add,
                        //         agreementCard_add: data.template.agreementCard_add,
                        //         secrerycontCardBefore_add: data.template.secrerycontCardBefore_add,
                        //         formrelation: {agreementCard_add: ['secrerycontCardBefore_add', 'secrerycontCardAfter_add']}
                        //     };
                        // } else if (agreementType === 'traincont') {
                        //     baseForm = 'traincontBaseCard_add'
                        //     template = {
                        //         traincontCardAfter_add: data.template.traincontCardAfter_add,
                        //         traincontBaseCard_add: data.template.traincontBaseCard_add,
                        //         traincontCardBefore_add: data.template.traincontCardBefore_add,
                        //         formrelation: {traincontBaseCard_add: ['traincontCardBefore_add', 'traincontCardAfter_add']}
                        //     };
                        // }else{
                        //     template = data.template
                        // }
                        // 自定义的协议注册
                        let registed = this.props.registed;
                        let temp = deepCopy(template);
                        for (let key in temp) {
                            if(temp.hasOwnProperty(key) && temp[key].moduletype){
                                if(!registed.includes(temp[key].code)) {
                                    temp[key].moduletype === 'form' && this.props.use.form(temp[key].code);
                                    temp[key].moduletype === 'table' && this.props.use.editTable(temp[key].code);
                                }
                        　　}
                        }
                        props.meta.addMeta(template);
                        let contractnum = pk_agreements;
                        let paramObj = {
                            agreementType: agreementType,
                            baseForm,
                            beforeForm: agreementType + "CardBefore_add",
                            afterForm: agreementType + "CardAfter_add"
                        };
                        // this.setDataBeforeFormKey(props, paramObj);
                        // 获取可编辑的key
                        let items = props.meta.getMeta()[agreementType + "CardAfter_add"].items;
                        let baseItems = props.meta.getMeta()[baseForm].items;
                        let len = items.length;
                        let baseLen = baseItems.length;
                        let editColumn = [];
                        for (let j = 0; j < baseLen; j++) {
                            if (baseItems[j].visible === true && baseItems[j].disabled === false) {
                                editColumn.push(baseItems[j].attrcode)
                            }
                        }
                        for (let i = 0; i < len; i++) {
                            if (items[i].visible === true && items[i].disabled === false) {
                                editColumn.push(items[i].attrcode)
                            }
                        }
                        this.setState({
                            formVisible: true,
                            listVisible: false,
                            formrelation: formrelationData[baseForm],
                            editColumn,
                            contractnum,
                            baseForm
                        }, ()=> {
                            let ifProp = rows[0].values.ifprop && rows[0].values.ifprop.value;
                            form.setFormItemsDisabled(baseForm, {
                                probmonth: !ifProp,
                                prop_unit: !ifProp,
                                probegindate: !ifProp,
                                probenddate: !ifProp,
                                probegindate1: !ifProp,
                                probenddate1: !ifProp
                            });
                            form.setFormItemsRequired(baseForm, {
                                probmonth: ifProp,
                                prop_unit: ifProp,
                                probegindate: ifProp,
                                probenddate: ifProp,
                                probegindate1: ifProp,
                                probenddate1: ifProp
                            });
                            // let formData = transRadio(rows, true, ["Y", "N"], ['isrefer', 'ifprop', 'lastflag', 'isrefer_old', 'ifprop_old', 'lastflag_old'], [json['cm6011-000057'], json['cm6011-000058']]); // ['是', '否']
                            form.setAllFormValue({[baseForm]: {rows: rows}});
                            form.setFormStatus(baseForm, 'edit');
                        })
                    }
                }
            })
        }
    }

    // 将表单模板key值改变
    // setDataBeforeFormKey(props, paramObj) {
    //     let state = this.state;
    //     let baseMeta = props.meta.getMeta()[paramObj['baseForm']];
    //     let agreementType = paramObj['agreementType'];
    //     // 培训协议会多展现几个字段
    //     if (agreementType === 'traincont') {
    //         baseMeta.items.map(obj => {
    //             switch (obj.attrcode) {
    //                 case 'pk_psnjob.pk_org':
    //                     obj.visible = true;
    //                     break;
    //                 case 'pk_psnjob.pk_dept':
    //                     obj.visible = true;
    //                     break;
    //                 case 'pk_psnjob.pk_post':
    //                     obj.visible = true;
    //                     break;
    //                 case 'pk_psndoc.id':
    //                     obj.visible = true;
    //                     break;
    //                 default:
    //                     break;
    //             }
    //         })
    //     } else {
    //         baseMeta.items.map(obj => {
    //             switch (obj.attrcode) {
    //                 case 'pk_psnjob.pk_org':
    //                     obj.visible = false;
    //                     break;
    //                 case 'pk_psnjob.pk_dept':
    //                     obj.visible = false;
    //                     break;
    //                 case 'pk_psnjob.pk_post':
    //                     obj.visible = false;
    //                     break;
    //                 case 'pk_psndoc.id':
    //                     obj.visible = false;
    //                     break;
    //                 default:
    //                     break;
    //             }
    //         })
    //     }
    //     // 变更前后展现不同的数据
    //     // 改dataAfter的键名
    //     let meta = props.meta.getMeta()[paramObj['beforeForm']];
    //     let meta2 = props.meta.getMeta()[paramObj['afterForm']];
    //     meta.items.map(obj => {
    //         obj.attrcode = obj.attrcode + '_old';
    //         obj.disabled = true;
    //         switch (obj.attrcode) {
    //             case 'creator_old':
    //                 obj.visible = false;
    //                 break;
    //             case 'creationtime_old':
    //                 obj.visible = false;
    //                 break;
    //             case 'modifier_old':
    //                 obj.visible = false;
    //                 break;
    //             case 'modifiedtime_old':
    //                 obj.visible = false;
    //                 break;
    //             default:
    //                 break;
    //         }
    //     });
    //     meta2.items.map(obj => {
    //         switch (obj.attrcode) {
    //             case 'creator':
    //                 obj.visible = false;
    //                 break;
    //             case 'creationtime':
    //                 obj.visible = false;
    //                 break;
    //             case 'modifier':
    //                 obj.visible = false;
    //                 break;
    //             case 'modifiedtime':
    //                 obj.visible = false;
    //                 break;
    //             default:
    //                 break;
    //         }
    //     });
    // }

    // 完成方法 调用新增保存接口
    doneHandle() {
        const {baseForm, agreementType, formrelation} = this.state;
        let {json, pageid} = this.props;
        //根据不同的协议类型修改字段的必输
        let bodys_code = null;
        let billType = 'form';
        let ifprop = this.props.form.getFormItemsValue(baseForm, 'ifprop').value === 'Y'; //是否试用
        if (agreementType === 'postcont' && ifprop) {
            let begindate1 = this.props.form.getFormItemsValue(baseForm, 'probegindate').value; //试用开始日期
            let enddate1 = this.props.form.getFormItemsValue(baseForm, 'probenddate').value; //试用结束日期
            let trmbegindate = this.props.form.getFormItemsValue(baseForm, 'begindate').value; //协议开始日期
            let trmenddate = this.props.form.getFormItemsValue(baseForm, 'enddate').value; // 协议结束日期
            if (trmbegindate && trmbegindate !== '') {
                let trmTimeNum = parseInt(new Date(trmbegindate).getTime());
                let proTimeNum = parseInt(new Date(begindate1).getTime());
                if (proTimeNum < trmTimeNum) {
                    toast({color: 'danger', content: json['cm6011-000132']}); /*【试用开始日期】不能小于【协议开始日期】！*/
                    return;
                }
            }
            if (trmenddate && trmenddate !== '') {
                let trmTimeNum = parseInt(new Date(trmenddate).getTime());
                let proTimeNum = parseInt(new Date(enddate1).getTime());
                if (proTimeNum > trmTimeNum) {
                    toast({color: 'danger', content: json['cm6011-000133']}); /*【试用结束日期】不能大于【协议结束日期】！*/
                    return;
                }
            }
        }
        if(formrelation.length > 0){
            bodys_code = formrelation;
            billType = 'extcard';
        }
        saveValidate(this.props, baseForm, baseForm, bodys_code, billType).then(()=>{
            if (this.props.form.isCheckNow(baseForm, "danger")) {
                let agreementData = this.props.form.getAllFormValue(baseForm, true);
                let paramObj = {
                    agreementData: {
                        agreementData: agreementData,
                    },
                    agreementType: this.state.agreementType,
                    isRefer: false,
                    pk_conts: this.state.contractnum,
                    editableItem: this.state.editColumn,
                    addAgreementPks: this.state.addAgreementPks
                };
                ajax({
                    url: '/nccloud/hrcm/agreement/ChangeSaveAction.do',
                    data: paramObj,
                    success: (result) => {
                        if (result.success) {
                            // 校验
                            if (result.data.validate) {
                                if (result.data.validate[0] !== null && result.data.validate[1].length === 0) { // 全部不变
                                    promptBox({
                                        color: 'info',
                                        title: json['cm6011-000144'], /*错误信息*/
                                        content: json['cm6011-000149'] + result.data.validate[0] + json['cm6011-000150'], /*下列人员：【刘良平, 100902093】的协议记录没有发生任何变更，不能保存！*/
                                        beSureBtnName: json['cm6011-000129'], /*关闭*/
                                        hasCloseBtn: false,
                                        noFooter: false,
                                        noCancelBtn: true,
                                    });
                                    return;
                                }
                                if (result.data.validate[0] !== null && result.data.validate[1].length > 0) { // 部分改变
                                    promptBox({
                                        color: 'info',
                                        title: json['cm6011-000144'], /*错误信息*/
                                        content: json['cm6011-000149'] + result.data.validate[0] + json['cm6011-000151'], /*下列人员：【李贵, 2212123】的协议记录没有发生任何变更，不能保存，系统将对其它人员进行保存，请问是否继续？*/
                                        beSureBtnName: json['cm6011-000057'], /*是*/
                                        cancelBtnName: json['cm6011-000058'], /*否*/
                                        hasCloseBtn: false,
                                        noFooter: false,
                                        noCancelBtn: false,
                                        beSureBtnClick: () => {
                                            let paramVO = {
                                                agreementData: {
                                                    agreementData: agreementData,
                                                },
                                                agreementType: this.state.agreementType,
                                                isRefer: false,
                                                pk_conts: this.state.contractnum,
                                                editableItem: this.state.editColumn,
                                                saveFlag: true,
                                                addAgreementPks: this.state.addAgreementPks
                                            }
                                            ajax({
                                                url: '/nccloud/hrcm/agreement/ChangeSaveAction.do',
                                                data: paramVO,
                                                success: (result) => {
                                                    this.effectiveData(result, json);
                                                }
                                            })
                                        },
                                    });
                                }
                            } else {
                                this.effectiveData(result, json);
                            }
                        }
                        this.setState({
                            tableId: ''
                        })
                    }
                });
            }
        })
       
    }

    /**
     * 确认是否生效
     * @param result
     * @param json
     */
    effectiveData(result, json) {
        let agreementPks = [];
        // for (let i = 0; i < result.data.length; i++) {
        //     agreementPks += result.data[i].pk_agreement;
        //     if (i < result.data.length - 1) {
        //         agreementPks += ','
        //     }
        // }
        !!result.data.length && result.data.map((item, index)=>{
            agreementPks.push(item.pk_agreement);
        })
        this.setState({
            saveFlag: true,
            effectivePks: agreementPks
        }, () => {
            if (this.state.saveFlag) {
                promptBox({
                    color: 'info',
                    title: json['cm6011-000071'], /*生效*/
                    content: json['cm6011-000048'], /*是否立即生效？*/
                    beSureBtnName: json['cm6011-000057'], /*是*/
                    cancelBtnName: json['cm6011-000058'], /*否*/
                    hasCloseBtn: false,
                    noFooter: false,
                    noCancelBtn: false,
                    beSureBtnClick: () => {
                        ajax({
                            url: '/nccloud/hrcm/agreement/ChangeEffectiveAction.do',
                            data: {
                                pk_agreements: this.state.effectivePks
                            },
                            success: (result) => {
                                if (result.success) {
                                    //保存成功后的生效操作
                                    toast({color: 'success', content: json['cm6011-000136']}); /*保存并生效成功！*/
                                    this.setState({
                                        listVisible: false,
                                        formVisible: false,
                                        setModalVisible: false,
                                    });
                                }
                            }
                        })
                    },
                    cancelBtnClick: () => {
                        this.setState({isRefer: false}, () => {
                            //保存成功后的取消生效操作
                            toast({color: 'success', content: json['cm6011-000005']}); /*保存成功！*/
                            this.setState({
                                listVisible: false,
                                formVisible: false,
                                setModalVisible: false,
                            });
                            this.props.getMainTableData();
                        })
                    }
                });
            }
        });
    }

    // 点击生效之后的提示
    addSaveAfterTips(message, title) {
        let json = this.props.json;
        promptBox({
            color: 'danger',
            title: title, // 确认继续
            content: message,
            noFooter: false,
            noCancelBtn: false,
            beSureBtnName: json['cm6011-000057'], // 是
            cancelBtnName: json['cm6011-000057'], // 否
            beSureBtnClick: this.doneHandle.bind(this),
            hasCloseBtn: false
        })
    }

    cancelBtnClick() {
        this.setState({
            step: 0
        })
        this.props.setNewIncreasedDis(false)
        if (this.props.refreshTableList) {
            this.props.refreshTableList()
        }
    }

    onClose() {
        this.setState({
            step: 0,
            tableId: ''
        })
        this.setNewIncreasedDis(false)
    }

    // 上一步的回调
    prevHandle() {
        let props = this.props;
        let {form, editTable} = props;
        if (this.state.listVisible) { // 第一个上一步
            this.setState({
                step: this.state.step--,
                listVisible: false,
                tableId: ''
            });
        }
        if (this.state.formVisible) { //第二个上一步
            this.setState({
                step: this.state.step--,
                listVisible: true,
                formVisible: false,
                tableId: 'releasecontlist'
            }, () => {
                editTable.setTableData('releasecontlist', this.state.rows);
                editTable.selectAllRows('releasecontlist', true);
            });
        }
    }

    // 调用协议编码回滚接口
    CodeRollBaceAction() {
        let props = this.props
        let state = this.state
        let contractnum = state.contractnum
        let codeList = []
        if (contractnum && contractnum.indexOf(',') !== -1) {
            codeList = contractnum.split(',')
        } else {
            codeList.push(contractnum)
        }
        let paramObj = {
            pk_org: props.pkOrg,
            codeList: codeList
        }
        ajax({
            url: '/nccloud/hrcm/common/CodeRollBackAction.do',
            data: paramObj,
            success: (result) => {
                if (result.success) {

                }
            }
        })
    }

    beforeEventHandle(props, moduleId, key, value, record) {
        let {agreementType} = this.state;
        if (key === 'pk_conttext') {
            let that = this;
            let meta = that.props.meta.getMeta();
            let pk_org = this.props.pkOrg;
            meta[agreementType + 'CardAfter_add'].items.find(item => item.attrcode === key).queryCondition = function () {
                return {
                    "pk_org": pk_org,
                    "GridRefActionExt": "nccloud.web.hrcm.make.sqlbuilder.ContModelGridSqlBuilder",
                    "agreementType": agreementType
                }
            };
            that.props.meta.setMeta(meta);
        }else if( key === 'pk_post'){
            let pk_dept = record['pk_psnjob.pk_dept.pk_dept'] && record['pk_psnjob.pk_dept.pk_dept'].value;
            if(!!pk_dept){
                let that = this;
                let meta = that.props.meta.getMeta();
                meta[agreementType + 'CardAfter_add'].items.find(item => item.attrcode === key).queryCondition = function () {
                    return {
                        "pk_dept" : pk_dept
                    }
                };
                that.props.meta.setMeta(meta);
            }
        }
        return true;
    }

    afterEventHandle(props, moduleId, key, value, changedrows, index, record) {
        // 设置要是否试用时必须编辑试用的表单框
        let agreementType = this.state.agreementType;
        let json = this.props.json;
        const {baseForm} = this.state
        chectFormAction(key, baseForm, props, [agreementType + 'CardAfter_add'], '60110503');

        // 培训协议，判断培训日期的校验
        if (agreementType === 'traincont') {
            //培训开始日期,培训结束日期
            if (key === 'trmbegindtate' || key === 'trmenddate') {
                let trmbegindtate = this.props.form.getFormItemsValue(moduleId, 'trmbegindtate').value;
                let trmenddate = this.props.form.getFormItemsValue(moduleId, 'trmenddate').value;
                if (trmbegindtate && trmenddate) {
                    //校验
                    if (new Date(trmbegindtate).getTime() > new Date(trmenddate).getTime()) {
                        promptBox({
                            color: 'info',
                            title: json['cm6011-000066'], /*警告*/
                            content: json['cm6011-000137'], /*培训结束日期必须在培训开始日期之后！*/
                            beSureBtnName: json['cm6011-000028'], /*确定*/
                            hasCloseBtn: true,
                            noFooter: false,
                            noCancelBtn: true,
                        });
                        if (key === 'trmbegindtate') {
                            this.props.form.setFormItemsValue(moduleId, {'trmbegindtate': {value: null}});
                        }
                        if (key === 'trmenddate') {
                            this.props.form.setFormItemsValue(moduleId, {'trmenddate': {value: null}});
                        }
                        return;
                    }

                }
            }
            //培训天数
            if (key === 'traindays') {
                let traindays = this.props.form.getFormItemsValue(moduleId, 'traindays').value;
                if (traindays) {
                    if (parseInt(traindays) < 0) {
                        toast({color: 'warning', content: json['cm6011-000138']}); /*培训天数不能小于0！*/
                        this.props.form.setFormItemsValue(moduleId, {'traindays': null});
                        return;
                    }
                }
            }
        }

        //协议期限和协议期限单位
        if (key === 'termmonth' || key === 'agreement_unit') {
            let num = this.props.form.getFormItemsValue(moduleId, 'termmonth').value; //协议期限
            if (parseInt(num) < 0) {
                toast({color: 'warning', content: json['cm6011-000139']}); /*协议期限不能小于0！*/
                this.props.form.setFormItemsValue(moduleId, {'termmonth': null});
                return;
            }
        }
        //协议结束日期
        if (key === 'enddate') {
            let values = this.props.form.getFormItemsValue(moduleId, 'enddate');
            let enddate = values.value;
            let begindate = this.props.form.getFormItemsValue(moduleId, 'begindate').value;
            if (begindate !== null && begindate !== '' && enddate !== null && enddate !== '') {
                //校验
                if (new Date(begindate).getTime() > new Date(enddate).getTime()) {
                    promptBox({
                        color: 'info',
                        title: json['cm6011-000066'], /*警告*/
                        content: json['cm6011-000140'], /*协议结束日期必须在协议开始日期之后！*/
                        beSureBtnName: json['cm6011-000028'], /*确定*/
                        hasCloseBtn: true,
                        noFooter: false,
                        noCancelBtn: true,
                    });
                    this.props.form.setFormItemsValue(moduleId, {'enddate': {value: null}});
                    return;
                }
            }
        }

        //试用期限和试用期限单位
        if (key === 'probmonth' || key === 'prop_unit') {
            let num1 = this.props.form.getFormItemsValue(moduleId, 'probmonth').value; //试用期限
            if (parseInt(num1) < 0) {
                toast({color: 'warning', content: json['cm6011-000141']}); /*试用期限不能小于0！*/
                this.props.form.setFormItemsValue(moduleId, {'probmonth': null});
                return;
            }

        }
        //试用结束日期
        if (key === 'probenddate') {
            let begindate = this.props.form.getFormItemsValue(moduleId, 'probegindate').value; //试用开始日期
            let enddate = this.props.form.getFormItemsValue(moduleId, 'probenddate').value; //试用结束日期

            if (begindate !== null && begindate !== '' && enddate !== null && enddate !== '') {
                if (new Date(enddate).getTime() < new Date(begindate).getTime()) {
                    promptBox({
                        color: 'info',
                        title: json['cm6011-000066'], /*警告*/
                        content: json['cm6011-000142'], /*试用结束日期必须在试用开始日期之后！*/
                        beSureBtnName: json['cm6011-000028'], /*确定*/
                        hasCloseBtn: true,
                        noFooter: false,
                        noCancelBtn: true,
                    });
                    this.props.form.setFormItemsValue(moduleId, {'probenddate': {value: null}});
                }
            }
        }
    }

    render() {
        const {form, pkOrg, editTable} = this.props;
        const {agreementType, tableId, baseForm} = this.state;
        
        return (
            <div className="addNew">
                {
                    this.state.setModalVisible ?
                        <NewIncreased
                            setModalVisible={this.state.setModalVisible}
                            {...this.props}
                            pk_org={pkOrg}
                            agFlag={true}
                            appCode={'60110503'}
                            isClearList={true}
                            ref={node => {
                                this.newIncreased = node
                            }}
                            prevHandle={this.prevHandle}
                            nextHandle={this.nextHandle}
                            doneHandle={this.doneHandle}
                            tableId={tableId}
                            onClose={this.onClose}>
                            <div className="addFormCon">
                                <div style={{display: this.state.listVisible ? '' : 'none'}}>
                                    {editTable.createEditTable('releasecontlist', {
                                        cancelCustomRightMenu: true,
                                        showIndex: true,
                                        showCheck: true,
                                    })}
                                </div>
                                {
                                    this.state.formVisible ?
                                        <div>
                                            {form.createForm(baseForm, {
                                                expandArr: [agreementType + 'CardAfter_add'],
                                                onBeforeEvent: this.beforeEventHandle,
                                                onAfterEvent: this.afterEventHandle
                                            })}
                                        </div> : null
                                }
                            </div>
                        </NewIncreased> :
                        null
                }
            </div>
        )
    }
}

export default AddNew
